<?php
// +----------------------------------------------------------------------
// | 老汉的项目
// +----------------------------------------------------------------------

namespace app\admin\controller;
use app\common\controller\Backend;

//流量统计
class Flow extends Backend
{
    protected $model = null;
    protected $noNeedRight = ['index','chartFlow','chartDayFlow'];

    public function _initialize() {
        parent::_initialize();
        $this->model = new \app\admin\model\Flow();
    }

    public function index(){
        $this->model->saveflow();
    }

    //获取表格数据
    public function chartFlow(){
        if($this->request->isAjax()){
            $param = $this->request->param();
            //时间
            $days = $this->model->getDaysList($param['starttime'],$param['endtime']);
            //数据
            $data = $this->model->getChartList($days);

            $result['data']   = $data;
            $result['days']   = array_column($days,'show');
            $result['type']   = ['电脑','手机'];
            return json(['code'=>1,'msg'=>'获取成功','data'=>$result]);
        }else{
            return json(['code'=>0,'msg'=>'非法请求']);
        }
    }


    public function chartDayFlow(){
        if($this->request->isAjax()){
            $param = $this->request->param();
            //时间
            $days = $this->model->getHoursList($param['starttime'],$param['endtime']);
            //数据
            $data = $this->model->getHourChartList($days);

            $result['data']   = $data;
            $result['days']   = array_column($days,'show');
            $result['type']   = ['电脑','手机'];
            return json(['code'=>1,'msg'=>'获取成功','data'=>$result]);
        }else{
            return json(['code'=>0,'msg'=>'非法请求']);
        }
    }

}
